package controllers.interfaces.tenant;

import java.util.Map;

import controllers.BaseController;
import net.sf.json.JSONObject;
import play.Logger;
import producers.ISkillProducer;
import producers.SkillProducer;
import utils.Constant;
import utils.StringUtil;

public class Skills extends BaseController {
    /**
     * 技能组创建
     */
    public static void create(String id){
        String sid = Constant.UCPAAS_SID;
        String token = Constant.UCPAAS_TOKEN;
        String appId = params.get("appId"); 
        appId = Constant.UCPAAS_APPID; //测试使用
        String queueId = StringUtil.trim(params.get("queueId"));
        String options = params.get("options");
        JSONObject _options = new JSONObject();
        if(!StringUtil.isBlank(options)){
            _options = JSONObject.fromObject(options); 
        }
        ISkillProducer producer = new SkillProducer(sid,token,appId);
        Map<String,String> result = producer.create(sid, token, appId, queueId, _options);
        result.put("id", id);
        Logger.info("[%s]: id<%s>, sid<%s>, token<%s>, appId<%s>, queueId<%s>, options<%s>, result<%s>", "Create",id,sid,token,appId,queueId,options,result);
        renderJSON(result);
    }
    
    /**
     * 技能组更新
     * @param id
     */
    public static void update(String id){
        String sid = Constant.UCPAAS_SID;
        String token = Constant.UCPAAS_TOKEN;
        String appId = params.get("appId"); 
        appId = Constant.UCPAAS_APPID; //测试使用
        String queueId = StringUtil.trim(params.get("queueId"));
        String options = params.get("options");
        JSONObject _options = new JSONObject();
        if(!StringUtil.isBlank(options)){
            _options = JSONObject.fromObject(options); 
        }
        ISkillProducer producer = new SkillProducer(sid,token,appId);
        Map<String,String> result = producer.update(sid, token, appId, queueId, _options);
        result.put("id", id);
        Logger.info("[%s]: id<%s>, sid<%s>, token<%s>, appId<%s>, queueId<%s>, options<%s>, result<%s>", "Update",id,sid,token,appId,queueId,options,result);
    }
    
    /**
     * 技能组删除
     * @param id
     */
    public static void destroy(String id){
        String sid = Constant.UCPAAS_SID;
        String token = Constant.UCPAAS_TOKEN;
        String appId = params.get("appId"); 
        appId = Constant.UCPAAS_APPID; //测试使用
        String queueId = params.get("queueId");
        ISkillProducer producer = new SkillProducer(sid,token,appId);
        Map<String,String> result = producer.destroy(sid, token, appId, queueId);
        result.put("id", id);
        Logger.info("[%s]: id<%s>, sid<%s>, token<%s>, appId<%s>, queueId<%s>,", "Destroy",id,sid,token,appId,queueId);
    }
    
}
